/**
 * Project Reactor
 */


#include "InetAddress.h"

/**
 * InetAddress implementation
 */


/**
 * @param ip
 * @param port
 */
InetAddress::InetAddress(const string & ip, unsigned short port) {
    bzero(&m_addr,sizeof(m_addr));
    m_addr.sin_family = AF_INET;
    m_addr.sin_port = htons(port);
    m_addr.sin_addr.s_addr = inet_addr(ip.c_str());
}

/**
 * @param addr
 */
InetAddress::InetAddress(const struct sockaddr_in & addr) {
    bzero(&m_addr,sizeof(m_addr));
    m_addr = addr;
}

InetAddress::~InetAddress() {

}

/**
 * @return string
 */
string InetAddress::getIP() {
    return inet_ntoa(m_addr.sin_addr);
}

/**
 * @return unsigned short
 */
unsigned short InetAddress::getPort() {
    return ntohs(m_addr.sin_port);
}

/**
 * @return struct sockadd_in *
 */
struct sockaddr_in * InetAddress::getInetAddressPtr() {
    return &m_addr;
}